#include "WorldSessionMgr.h"

CWorldSessionMgr::CWorldSessionMgr(void)
{
}

CWorldSessionMgr::~CWorldSessionMgr(void)
{
}

void CWorldSessionMgr::AddSession(CWorldSession* session)
{
	if(!session)
		return;
	m_QueSession.push(session);
}

void CWorldSessionMgr::Update()
{
	while ( m_QueSession.size() != 0)
	{
		CWorldSession* session =  m_QueSession.front();
		_AddSession(session);
		m_QueSession.pop();
	}

	UpdateSession();
}

void CWorldSessionMgr::UpdateSession()
{
	std::map<uint32,CWorldSession*>::iterator iter = m_mapSession.begin();
	for (;iter != m_mapSession.end();)
	{
		if(iter->second->isClose())
		{
			delete iter->second;
			m_mapSession.erase(iter++);
			continue;
		}
		iter->second->Update();
		++iter;
	}
}

static int sIndex = 0;
void CWorldSessionMgr::_AddSession(CWorldSession* session)
{
	if (!session)
		return;
	m_mapSession[sIndex] = session;
	sIndex++;
}